<?php
	/* **********************************************************/
	/* Arcans Project (2010)                                    */
	/* Jeu sous forme d'application web entièrement conçu       */
	/* et réalisé par Killian Le Maitre                         */
	/* Jeu sous licence GNU GPL v3 (voir NOTICE et COPYING)     */
	/* **********************************************************/

	//***********************
	//classe de gestion mysql
	//***********************
	class MysqlClass {
		//propriétés :
		private $db_infos;
		private $db_rep;
		//constructeur :
		function __construct($level) {
			$bdd_xml = new DomDocument();
			$bdd_xml->load("xml/bdd.xml");
			$list_connect = $bdd_xml->getElementsByTagName("connect");
			foreach ($list_connect as $elt) {
				$att = $elt->getAttribute("level");
				if ($att == $level) {
					$this->db_infos["host"] = $elt->getElementsByTagName("server")->item(0)->textContent;
					$this->db_infos["user"] = $elt->getElementsByTagName("user")->item(0)->textContent;
					$this->db_infos["pwd"] = $elt->getElementsByTagName("pwd")->item(0)->textContent;
					$this->db_infos["db"] = $elt->getElementsByTagName("db")->item(0)->textContent;
					break;
				}
			}
		}
		//méthodes :
			//appel de requetes
		public function resultFun($type, $table, $question) {
			$connection = mysql_connect($this->db_infos["host"], $this->db_infos["user"], $this->db_infos["pwd"]);
			mysql_select_db($this->db_infos["db"], $connection);
			switch ($type) {
				case "count" : $this->countFun($table, $question); break;
				case "insert" : $this->insertFun($table, $question); break;
				case "select" : $this->selectFun($table, $question); break;
				case "selectm" : $this->selectmFun($table, $question); break;
				case "delete" : $this->deleteFun($table, $question); break;
				case "update" : $this->updateFun($table, $question); break;
			}
			return $this->db_rep;
			mysql_close($connection);
		}
			//requete "count"
		private function countFun($table, $question) {
			$this->db_rep = mysql_query("select count(*) as 'reponse' from ".$table." where ".$question);
			$this->db_rep = mysql_fetch_array($this->db_rep);
			$this->db_rep = $this->db_rep["reponse"];
		}
			//requete "insert"
		private function insertFun($table, $question) { $this->db_rep = mysql_query("insert into ".$table." ".$question); }
			//requete "select" pour un élément
		private function selectFun($table, $question) {
			$this->db_rep = mysql_query("select * from ".$table." where ".$question);
			$this->db_rep = mysql_fetch_array($this->db_rep);
		}
			//requete "select" pour zero, un ou plusieurs éléments
		private function selectmFun($table, $question) { $this->db_rep = mysql_query("select * from ".$table." ".$question); }
			//requete "delete"
		private function deleteFun($table, $question) { $this->db_rep = mysql_query("delete from ".$table." where ".$question); }
			//requete "update"
		private function updateFun($table, $question) { $this->db_rep = mysql_query("update ".$table." set ".$question); }
	}
?>